Mapping with a CNN |
The fully connected layers of a convolutional neural network can be used to implement a traditional multilayer network. Las capas completamente conectadas de una red neuronal convolucional pueden ser usados para implementar una red multicapa tradicional. |
Problem 1 |
Repeat the problem in Mapping > Sine and Cosine to learn the sine and cosine functions using a convolutional neural network. Create a new project, select Convolutional Neural Network and General purpose in the new project dialog. Also check the options to generate the files BuildTrainSet.lab and BuildValidSet.lab. The project name must be ConvSinCos. Repita el problema en Mapping > Sine and Cosine para aprender las funciones seno y coseno usando una red neural convolucional. Cree un nuevo proyecto, seleccione Convolutional Neural Network y General purpose en el diálogo de nuevo proyecto. También seleccione las opciones para generar los archivos BuildTrainSet.lab y BuildValidSet.lab. El nombre del proyecto debe ser ConvSinCos. |
Step A |
Edit the BuildTrainSet.lab file, then execute the code. Edite el archivo BuildTrainSet.lab, entonces ejecute el código |
ConvSinCos\BuildTrainSet.lab |
int numCases = 1024; //_________________________________________ 1. Build and save the input Vector x; x.CreateSeries(0.0, 2.0*3.1415926, numCases); // 0, ..., 6.28 Matrix trainSetInput; trainSetInput = x; trainSetInput.Save(); //_________________________________________ 2. Build and save the target Vector sinx = sin(x); Vector cosx = cos(x); Matrix trainSetTarget = sinx; trainSetTarget.AppendRight(cosx); trainSetTarget.Save(); |
Step B |
Edit the BuildValidSet.lab file, then execute the code. Finally, click on "Graph" in the toolbar. Edite el archivo BuildValidSet.lab, entonces ejecute el código. Finalmente, haga clic en "Graph" en la barra de herramientas. |
ConvSinCos\BuildValidSet.lab |
int numCases = 512; //_________________________________________ 1. Build and save the input Vector x; x.CreateRandom(numCases, 0.0, 2*3.1415926); Matrix validSetInput; validSetInput = x; validSetInput.Save(); //_________________________________________ 2. Build and save the target Vector sinx = sin(x); Vector cosx = cos(x); Matrix validSetTarget = sinx; validSetTarget.AppendRight(cosx); validSetTarget.Save(); |
Step C |
Edit the Train.lab file, then execute the code. Edite el archivo Train.lab, entonces ejecute el código. |
ConvSinCos\Train.lab |
//_________________________________________ 1. Network setup ConvNet net; net.Create(1, 1, 1, 2); net.SetInRange(0.0, 2.0*3.1416); net.SetOutRange(-1.0, 1.0); net.SetFullLayer(0, 1, 10); // logsig=1, Hidden layer net.SetFullLayer(1, 1, 2); // logsig=1, Output layer //_________________________________________ 2. Load training set Tensor trainSetInput; trainSetInput.LoadCsv(1, 1, 1); Tensor trainSetTarget; trainSetTarget.LoadCsv(2, 1, 1); net.SetTrainSet(trainSetInput, trainSetTarget, false); //_________________________________________ 3. Train net.TrainSimAnneal( 10, //Number of Temperatures 10, //Number Iterations 15, //Initial Temperature 0.001, //Final Temperature true, // Is Cooling Schedule Linear? 4, // Number of Cycles 1.0e-6, // Goal (desired mse) true // Use Singular Value Decomposition ); net.TrainConjGrad(2500, 1.0e-10); net.Save(); |
Step D |
Edit the CheckTrain.lab file, then execute the code to check the training. Edite el archivo CheckTrain.lab, entonces ejecute el código para verificar el entrenamiento. |
ConvSinCos\CheckTrain.lab |
Step E |
Edit the Validation.lab file, then execute the code to validate the performance of the network. Edite el archivo CheckTrain.lab, entonces ejecute el código para validar el desempeño de la red neuronal. |
ConvSinCos\Validation.lab |
//_________________________________________ 1. Load the validation set Tensor validSetInput; validSetInput.LoadCsv(1, 1, 1); Tensor validSetTarget; validSetTarget.LoadCsv(2, 1, 1); //_________________________________________ 2. Load the ANN ConvNet net; net.Load(); //_________________________________________ 3. Run Tensor output; net.Run(validSetInput, output); double mse = output.ComputeMse(validSetTarget); //_________________________________________ 4. Relative Error Vector error; output.ComputeRelError(validSetTarget, error); XyChart validation; validation.SetCaption("case", false, "Relative Error", false); validation.AddGraphY(error, "Relative Error", 2, 1, 0, 255, 0); validation.SetLogScale(false, true); validation.SetLimits(0, validSetTarget.GetCount(), 1.0e-10, 1.0); validation.SetColorMode(2); validation.SaveAndShow(); validation.SavePDF(0.0); validation.SaveEMF(); |
Step F |
Add a new file called TrainSim.lab to the project. Execute the program, then click on "Graph" in the toolbar to simulate the network using the training set. Agregue un archivo nuevo llamado TrainSim.lab al proyecto. Ejecute el programa, entonces haga clic en "Graph" en la barra de herramientas para simular la red usar el conjunto de datos de entrenamiento. |
ConvSinCos\TrainSim.lab |
ConvNet net; net.Load(); //_________________________________________ 1. Input Tensor trainSetInput; trainSetInput.LoadCsv(1, 1, 1); //_________________________________________ 2. Target Tensor trainSetTarget; trainSetTarget.LoadCsv(2, 1, 1); Matrix target; trainSetTarget.GetSideMatrix(0, target); // Extract one slide Vector sinTarget = target.GetColVec(0); // Extract one column vector Vector cosTarget = target.GetColVec(1); // Extract one column vector //_________________________________________ 3. ANN output Tensor output; net.Run(trainSetInput, output); Matrix out; output.GetSideMatrix(0, out); Vector sinNN = out.GetColVec(0); Vector cosNN = out.GetColVec(1); |
Step G |
Add a new file called ValidSim.lab to the project. Execute the program, then click on "Graph" in the toolbar to simulate the network using the validation set. Agregue un archivo nuevo llamado ValidSim.lab al proyecto. Ejecute el programa, entonces haga clic en "Graph" en la barra de herramientas para simular la red usar el conjunto de datos de validación. |
ConvSinCos\ValidSim.lab |
ConvNet net; net.Load(); //_________________________________________ 1. Input Tensor validSetInput; validSetInput.LoadCsv(1, 1, 1); Matrix input; validSetInput.GetFrontMatrix(0, input); Vector in = input.GetColVec(0); //_________________________________________ 2. Target Tensor validSetTarget; validSetTarget.LoadCsv(2, 1, 1); Matrix target; validSetTarget.GetSideMatrix(0, target);// Extract one slide Vector sinTarget = target.GetColVec(0); // Extract one column vector Vector cosTarget = target.GetColVec(1); // Extract one column vector //_________________________________________ 3. ANN output Tensor output; net.Run(validSetInput, output); Matrix out; output.GetSideMatrix(0, out); Vector sinNN = out.GetColVec(0); Vector cosNN = out.GetColVec(1); |